package com.example.administrator.myproject.Prensent;

import android.content.Context;
import android.os.SystemClock;
import android.widget.Toast;

import com.example.administrator.myproject.Model.UserModel;
import com.example.administrator.myproject.View.MainActivity;
import com.example.administrator.myproject.beans.UserInfo;

import java.util.List;

import rx.Scheduler;
import rx.Subscriber;
import rx.Subscription;

/**
 * Created by Administrator on 2016-11-30.
 */
public class UserPresenter {
    private MainActivity mLoginView;
    private UserModel mLoginModel;
    private Context mContext;
    public UserPresenter(Context context, MainActivity baseCustomView) {
        this.mContext = (Context) baseCustomView;
        this.mLoginView = baseCustomView;
        mLoginModel = new UserModel();
    }

    public void  getDataFromGithub(String name,String psw)
    {
        SystemClock.sleep(2000);
      //  mLoginView.showPm
        Subscription subscribe = mLoginModel.getDataFromGithub(name, psw)
             //   .subscribe(Scheduler.io());//在非线程进行耗时操作
             //   .observeOn(AndroidSchedulers.mainThread())//在UI线程进行观察监听
            .subscribe(new Subscriber<List<UserInfo>>() {//开始订阅观察监听
                @Override
                public void onCompleted() {
                    //  mLoginView.hideProgressDialog();
                }

                @Override
                public void onError(Throwable e) {
                    // mLoginView.showError("--->>" + e.getMessage());
                    Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onNext(List<UserInfo> githubUsers) {
                    //  mLoginView.hideProgressDialog();
                    mLoginView.getDataSuccess(githubUsers);
                }
            });

    }

}
